package org.example.yiyu.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.yiyu.mapper.TagMapper;
import org.example.yiyu.model.Tag;
import org.example.yiyu.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class TagsServiceImpl implements TagService {


    private final TagMapper tagMapper;

    //创建标签
    @Override
    public Long addTag(Tag tag) {
        tagMapper.createTag(tag);
        return tag.getId();
    }

    //删除标签
    @Override
    public void removeTag(Long id) {

        tagMapper.deleteTag(id);
    }

    //修改标签
    @Override
    public void modifyTag(Tag tag) {
        tagMapper.updateTag(tag);
    }

    // 获取所有标签
    public List<Tag> getAllTags() {
        return tagMapper.getAllTags();
    }

    // 批量删除某标签下的所有日记
    public void deleteDiariesByTag(Long tagId) {
        tagMapper.deleteDiariesByTag(tagId);
    }

}

